﻿using Itech_Run.HttpApi.Shared.Result;
using Itech_Run.Helper.Attribute;
using Itech_Run.HttpApi.Shared;
using Itech_Run.Sys.Application.Contracts.Dto;
using Itech_Run.Sys.Application.Contracts.Service;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace Itech_Run.Sys.HttpApi.Controllers
{
    public class SysModuleController : BaseApiController
    {
        private readonly ISysModuleService _sysModuleService;
        public SysModuleController(ISysModuleService sysModuleService)
        {
            _sysModuleService = sysModuleService;
        }

        [HttpGet]
        public async Task<CustomResult> GetAsync(string id)
        {
            return new CustomResult(await _sysModuleService.GetAsync(id));
        }

        [HttpPost]
        public async Task<CustomResult> GetListAsync(SysModuleListDto listDto)
        {
            return new CustomResult(await _sysModuleService.GetListAsync(listDto));
        }

        [HttpGet]
        public async Task<CustomResult> GetSysModuleTreeAsync([Required] string application)
        {
            return new CustomResult(await _sysModuleService.GetSysModuleTree(application));
        }

        [HttpGet]
        public async Task<CustomResult> GetSysModulePermissionTreeAsync([Required] string application, [Required] string role)
        {
            return new CustomResult(await _sysModuleService.GetSysModulePermissionTree(role, application));
        }

        [ButtonAuth(ButtonAuthConst.add)]
        [HttpPost]
        public async Task<CustomResult> InsertAsync(SysModuleCreateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysModuleService.InsertAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.edit)]
        [HttpPost]
        public async Task<CustomResult> UpdateAsync(SysModuleUpdateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysModuleService.UpdateAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.delete)]
        [HttpPost]
        public async Task<CustomResult> DeleteAsync(string id)
        {
            await _sysModuleService.DeleteAsync(id);
            return GetSuccesResult();
        }

        [HttpGet]
        public async Task<CustomResult> GetSysModuleApiPathAsync()
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysModuleService.GetSysModuleApiPath(operateUser));
        }

        [HttpGet]
        public async Task<CustomResult> GetSysModuleButtonAuthAsync()
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _sysModuleService.GetSysModuleButtonAuth(operateUser));
        }
    }
}
